#include "Manager.h"
#include "MapIO.h"
#include "Move.h"
#include "Grass.h"
#include "Bird.h"
#include "OtherEle.h"
#include "Undoable.h"
#include "Undo.h"


int Manager :: map[LEVEL_HEIGHT / SIZEY][LEVEL_WIDTH / SIZEX];
Manager :: Manager(MapIO* mapIO, Dot* dot)
{
	this->io = mapIO;
	this->dot = dot;

	currentCmd = NULL;

	for(int i = 0; i < LEVEL_HEIGHT / SIZEY; i++)
	{
		for(int j = 0; j < LEVEL_WIDTH /SIZEX; j++)
			map[i][j] = -1;
	}
}

void Manager :: process()
{
	Uint8* keys = NULL;
	keys = SDL_GetKeyState(NULL);

	if(keys[SDLK_UP] || keys[SDLK_DOWN] || keys[SDLK_LEFT] || keys[SDLK_RIGHT])
		currentCmd = new Move(dot);
	else if(keys[SDLK_0] || keys[SDLK_1] || keys[SDLK_2] || keys[SDLK_3] || keys[SDLK_4] || keys [SDLK_5])
		currentCmd = new Bird(dot);
	else if(keys[SDLK_6])
		currentCmd = new Grass(dot);
	else if(keys[SDLK_7] || keys[SDLK_8] || keys[SDLK_9] || keys[SDLK_q])
		currentCmd = new OtherEle(dot);
	else if(keys[SDLK_LCTRL] && keys[SDLK_z])
		currentCmd = new Undo();

	if(currentCmd != NULL)
		currentCmd->process(keys);

	io->output();

	if(keys[SDLK_UP] || keys[SDLK_DOWN] || keys[SDLK_LEFT] || keys[SDLK_RIGHT])
		delete currentCmd;

	currentCmd = NULL;
}